package com.uvlab.sitespot.service.task;

import com.uvlab.sitespot.service.node.JxNode;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.LinkedHashMap;

/**
 * Created by Administrator on 2016/6/16 0016.
 */
public class JxRemoteTaskService {
    private LinkedHashMap items =new LinkedHashMap();
    RestTemplate restTemplate;
    private  String url="http://localhost:8084";
    public JxRemoteTaskService(){

    }

    public void init(String url){
        this.url=url;
    }
    public LinkedHashMap find() {
        restTemplate= new RestTemplate();
        items = restTemplate.getForObject(url+"/task", LinkedHashMap.class);
        return  this.items;
    }

    public JxTask get(String id){
        restTemplate=new RestTemplate();
        return restTemplate.getForObject(url+"/task/"+id,JxTask.class);

    }
    public JxTask add(JxTask task) {
        restTemplate= new RestTemplate();
        return  restTemplate.postForObject(url+"/task",task,JxTask.class);
    }

    public  void remove(String id){
        restTemplate= new RestTemplate();
        restTemplate.delete(url+"/task/"+id);
    }

    public void set(String id,JxTask task){
        restTemplate=new RestTemplate();
        restTemplate.put(url+"/task/"+id,task);
    }
}
